<?php
$this->headTitle()->prepend($this->translate('user_manager'). ' - ');
$this->headLink()->appendStylesheet($this->APP_STATIC_SERVER . '/skins/admin/default/css/form.css');
$this->headScript()
        ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate.js')
        ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.json-2.3.min.js');
?>

<div id="r-heading">
    <img src="<?php echo $this->APP_STATIC_SERVER . '/skins/admin/default/images/user.png'; ?>" alt=""/>
    <span><?php echo $this->translate('user_edit_page_title')?></span>
</div>
<?php
$message = $this->flashMessenger();
if($message){?>
    <div id="message"><ul><?php echo $message; ?></ul></div>
<?php }?>
<form id="frmEditUser" enctype="application/x-www-form-urlencoded" action="" method="post">
	<div class="r-left" style="width:70%; float:left;">
		<div class="row">
			<label for="username"><?php echo $this->translate('user_user_name')?></label>
			<input type="text" name="username" id="username" value="<?php echo $this->user->username?>" size="30" autocomplete="off" />
		</div>
		<div class="row">
			<label for="password"><?php echo $this->translate('user_password')?></label>
			<input type="password" name="password" id="password" value="" size="30" autocomplete="off" />
		</div>
		<div class="row">
			<label for="confirm_password" ><?php echo $this->translate('user_confirm_password')?></label>
			<input type="password" name="confirm_password" id="confirm_password" value="" size="30" />
		</div>
		<div class="row">
			<label for="full_name" ><?php echo $this->translate('user_full_name')?></label>
			<input type="text" name="full_name" id="full_name" value="<?php echo $this->user->full_name?>" size="40" />
		</div>
		<div class="row">
			<label for="email" ><?php echo $this->translate('user_email')?></label>
			<input type="text" name="email" id="email" value="<?php echo $this->user->email?>" size="40" />
		</div>
		<div class="row">
			<label for="role_id"><?php echo $this->translate('user_role')?></label>
			<select name="role_id" id="role_id">
                      <option value="" >---</option>
                      <?php if(isset($this->roles)){
                          foreach ($this->roles as $role){
                      ?>
                        <option <?php echo ($role->id == $this->user->role_id) ? 'selected="selected"' : '' ?> value="<?php echo $role->id ?>" ><?php echo $role->name ?></option>
                      <?php
                          }
                      }
                      ?>
			</select>
		</div>
            <div class="row" style="width:100%; clear: both;">
			<input class="button" type="submit" name="submit" id="submit" value="<?php echo $this->translate('common_save')?>" />
			<input class="button" type="reset" name="reset" id="reset" value="<?php echo $this->translate('common_reset')?>" />
		</div>
	</div>
</form>

<script type="text/javascript">
$(document).ready(function(){
    /**
     * Validate form
     */

    $('#frmEditUser').validate({
        rules: {
              full_name: {
                    required: true
              },
              username: {
                    required: true,
                    minlength: 5,
                    maxlength: 25,
                    remote: '<?php echo $this->url(array('check_type' => 'username'), 'core_user_check'); ?>?original=<?php echo $this->user->username; ?>'
              },
              email: {
                    required: true,
                    email: true,
                    remote: '<?php echo $this->url(array('check_type' => 'email'), 'core_user_check'); ?>?original=<?php echo $this->user->email; ?>'
              },
              confirm_password: {
                    equalTo: '#password'
              },
              role_id: {
                    required: true
              }
      },
      messages: {
            full_name: {
                  required: "<?php echo $this->translate('user_full_name_required'); ?>"
            },
            username: {
                required: "<?php echo $this->translate('user_user_name_required'); ?>",
                minlength: "<?php echo $this->translate('user_user_name_minlength'); ?>",
                maxlength: "<?php echo $this->translate('user_user_name_maxlength'); ?>",
                remote: "<?php echo $this->translate('user_user_name_exist'); ?>"
            },
            email: {
                required: "<?php echo $this->translate('user_email_required'); ?>",
                email: "<?php echo $this->translate('user_email_invalid'); ?>",
                remote: "<?php echo $this->translate('user_email_exist'); ?>"
            },
            confirm_password: {
                equalTo: "<?php echo $this->translate('user_confirm_password_error'); ?>"
            },
            role_id: {
                required: "<?php echo $this->translate('user_role_required'); ?>"
            }
        }
    });
});
</script>